<template>
   <el-radio-group v-model="model" @change="handleChange" :disabled="disabled">
        <el-radio v-for="(item,index) in codeData" :label="item.value" :key="index">{{item.text}}</el-radio>
    </el-radio-group>
</template>
<script>
import {codeProvider} from '../../../assets/js/provider.js'
export default {
    name: 'dx-radio',
    props:{
        value : {type: null ,default:''},
        codeType : {type:String,default:''},
        condition : {type:Object,default:()=>{}},
        disabled : {type:Boolean,default:false}
    },
    computed : {
        model : {
            get(){
                return this.val ? this.val : this.value;
            },
            set(value){
                this.val = value;
                this.$emit('input', value); // key code 
            }
        }
    },
    watch : {
        codeType(val){
            this.initData();
        },
        condition(val){
            this.initData();
        }
    },
    data(){

        return {
            val : this.value,
            codeData : []
        }
    },
    methods : {
        handleChange(val){
            this.$emit('change',val);
        },
        initData(){
            if(this.codeType){
                codeProvider.getList(this.codeType,this.condition||{}).then(resp=>{
                    this.codeData = resp;
                });
            }else{
                console.error('codeType is not empty!');
            }
        }  
    },
    created(){
        this.initData();
    },
    mounted(){

    }
}
</script>
<style scoped>

</style>

